package com.wjy.sfhcore.ui.fragment.list;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.wjy.sfhcore.R;
import com.wjy.sfhcore.ui.third_party.refresh.PullToRefreshListView;
import com.wjy.sfhcore.util.Tools;

/**
 * 此类用来替代 ListActivity, 用于2.x系统的兼容
 *
 * @author b456
 */
public abstract class BaseListFragment<D, L> extends
        BaseAdapterViewFragment<D, L, ListView> {
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.lib_list_content_simple,
                container, false);
        return view;
    }

    protected boolean isNeedDriverLine() {
        return true;
    }

    protected void initAdapterView(View view) {
        mAdapterViewBase = (PullToRefreshListView) view.findViewById(R.id.list);
        mAdapterView = mAdapterViewBase.getRefreshableView();
        View childView = initHeaderChildView();
        if (childView != null) {
            ((PullToRefreshListView) mAdapterViewBase)
                    .addHeaderChildView(childView);
        }
        mAdapterView.setOnItemClickListener(this);
        mAdapterView.setOnItemLongClickListener(this);
        mAdapterViewBase.getLoadingLayoutProxy().setLastUpdatedLabel(
                Tools.isEmpty(lastRefreshDate) ? ""
                        : getString(R.string.xlistview_header_last_time)
                        + Tools.trim(lastRefreshDate));
        if (!isNeedDriverLine()) {
            mAdapterView.setDivider(null);
        }
    }

    protected void setAdapter() {
        mAdapterView.setAdapter(animationAdapter);
    }
}